package com.naiterui.ehp.bs.pharmacist.controller.inner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.pharmacist.exception.ExceptionCodes;
import com.naiterui.ehp.bs.pharmacist.service.IPharmacistService;

import io.swagger.annotations.Api;

/**
 * @author guoyongxiang
 * @date 2019/12/4 21:31
 * @since 1.0.0
 */
@RequestMapping("pharmacist/inner/esign")
@RestController
@Api(tags = {SwaggerTag.PHARMACIST + SwaggerTag.INNER_API + SwaggerTag.CA_ESIGN})
public class PharmacistInnerEsignController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PharmacistInnerEsignController.class);

    @Autowired
    private IPharmacistService pharmacistService;

    /**
     * CA用户审核通知
     * 变更用户审核状态
     *
     * @param userId
     * @param status 1:通过, 2:不通过
     * @param reason
     *
     * @return
     */
    @PostMapping("auth/result")
    public ResponseVO<Void> authResult(Long userId, Integer status, String reason) throws BusinessException {
        LOGGER.info("用户审核状态通知 userId:{}, status:{}, reason:{}", userId, status, reason);
        pharmacistService.userAuth(userId, status, reason);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

    @PostMapping("perfect/sealimage")
    public ResponseVO<Void> perfectSealImage(String sealImage, Long pharmacistId) throws BusinessException {
        LOGGER.info("回写三方签名机构生成签章图片，pharmacistId {}, sealImage {}", pharmacistId, sealImage);
        pharmacistService.perfectSealImage(sealImage, pharmacistId);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS);
    }

}
